<template>
  <view class="content pt-30 pb-50 pl-20 pr-20">
    <view class="form-block pl-20 pr-20">
      <view class="pt-20" style="display: flex;">
        <view class="title-block">隐患信息</view>
      </view>
      <view class="item-block pt-20 pb-20 border-b-common">
        <view class="item-label"><text class="wraning-icon">*</text>隐患名称</view>
        <input class="item-input mr-30 text-r" placeholder="请输入隐患名称" placeholder-class="placeholder" v-model="params.htName" />
      </view>
      <view class="item-block pt-20 pb-20 border-b-common">
        <view class="item-label"><text class="wraning-icon">*</text>隐患等级</view>
        <view class="item-select" @click="() => levelState = true">
          <text v-if="params.levelName" class="mr-10">{{params.levelName}}</text>
          <text v-else class="item-default-text mr-10">请选择隐患等级</text>
          <u-icon name="arrow-right" size="26rpx" color="#CCCCCC"></u-icon>
        </view>
      </view>
      <view class="item-block pt-20 pb-20 border-b-common">
        <view class="item-label"><text class="wraning-icon">*</text>隐患类别</view>
        <view class="item-select" @click="() => categoryState = true">
          <text v-if="params.categoryName" class="mr-10">{{params.categoryName}}</text>
          <text v-else class="item-default-text mr-10">请选择隐患类别</text>
          <u-icon name="arrow-right" size="26rpx" color="#CCCCCC"></u-icon>
        </view>
      </view>
      <view class="item-block pt-20 pb-20 border-b-common">
        <view class="item-label"><text class="wraning-icon">*</text>隐患来源</view>
        <view class="item-select" @click="() => sourceState = true">
          <text v-if="params.sourceName" class="mr-10">{{params.sourceName}}</text>
          <text v-else class="item-default-text mr-10">请选择隐患来源</text>
          <u-icon name="arrow-right" size="26rpx" color="#CCCCCC"></u-icon>
        </view>
      </view>
      <view class="item-block pt-20 pb-20">
        <view class="item-label"><text class="wraning-icon">*</text>隐患地点</view>
        <view class="item-select">
          <input class="item-input text-r" style="width: 600rpx; max-width: 600rpx;" placeholder="请输入/选择隐患地点" placeholder-class="placeholder" v-model="params.place" />
          <u-icon name="map" size="40rpx" color="#3F99F7" @click="getLocationInfo()"></u-icon>
        </view>
      </view>
    </view>
    <view class="form-block mt-30 pl-20 pr-20">
      <view class="pt-20" style="display: flex;">
        <view class="title-block">检查信息</view>
      </view>
      <view class="item-block pt-20 pb-20 border-b-common">
        <view class="item-label"><text class="wraning-icon">*</text>检查类型</view>
        <view class="item-select" @click="() => checkTypeState = true">
          <text v-if="params.checkTypeName" class="mr-10">{{params.checkTypeName}}</text>
          <text v-else class="item-default-text mr-10">请选择检查类型</text>
          <u-icon name="arrow-right" size="26rpx" color="#CCCCCC"></u-icon>
        </view>
      </view>
      <view class="item-block pt-20 pb-20 border-b-common">
        <view class="item-label"><text class="wraning-icon">*</text>检查单位</view>
        <view class="item-select">
          <text v-if="params.checkDeptIdName" class="mr-10">{{params.checkDeptIdName}}</text>
          <text v-else class="item-default-text mr-10">请选择检查单位</text>
          <u-icon name="arrow-right" size="26rpx" color="#CCCCCC"></u-icon>
        </view>
      </view>
      <view v-if="params.checkDeptIdName" class="item-block pt-20 pb-20 border-b-common">
        <view class="item-label"><text class="wraning-icon">*</text>检查人</view>
        <view class="item-select">
          <text v-if="params.checkPeoIdName" class="mr-10">{{params.checkPeoIdName}}</text>
          <text v-else class="item-default-text mr-10">请选择检查人</text>
          <u-icon name="arrow-right" size="26rpx" color="#CCCCCC"></u-icon>
        </view>
      </view>
      <view class="item-block pt-20 pb-20 border-b-common">
        <view class="item-label">隐患形成原因</view>
        <input class="item-input mr-30 text-r" placeholder="请输入隐患形成原因" placeholder-class="placeholder" v-model="params.causeReason" />
      </view>
      <view class="item-block pt-20 pb-20 border-b-common">
        <view class="item-label">隐患描述</view>
        <input class="item-input mr-30 text-r" placeholder="请输入隐患描述" placeholder-class="placeholder" v-model="params.description" />
      </view>
      <view class="item-block pt-20 pb-20 border-b-common">
        <view class="item-label"><text class="wraning-icon"></text>所属风险点</view>
        <view class="item-select" @click="routeByUrl(`/pagesCommon/dangerPlaceList`)">
          <text v-if="riskName" class="mr-10">{{riskName}}</text>
          <text v-else class="item-default-text mr-10">请选择所属风险点</text>
          <u-icon name="arrow-right" size="26rpx" color="#CCCCCC"></u-icon>
        </view>
      </view>
      <view class="item-block pt-20 pb-20">
        <view class="item-label"><text class="wraning-icon">*</text>所属单位</view>
        <!-- <view class="item-select" @click="() => beCheckDeptIdState = true"> -->
        <view class="item-select" @click="routeByUrl('/pagesCommon/departmentList?paramsKey=beCheck&departmentState=1')">
          <text v-if="params.beCheckDeptIdName" class="mr-10">{{params.beCheckDeptIdName}}</text>
          <text v-else class="item-default-text mr-10">请选择所属单位</text>
          <u-icon name="arrow-right" size="26rpx" color="#CCCCCC"></u-icon>
        </view>
      </view>
    </view>
    <view class="form-block mt-30 pl-20 pr-20">
      <view class="pt-20" style="display: flex;">
        <view class="title-block">整改信息</view>
      </view>
      <view class="item-block pt-20 pb-20 border-b-common">
        <view class="item-label"><text class="wraning-icon">*</text>整改方式</view>
        <view class="item-radio">
          <u-radio-group v-model="params.rectificationType" size="32rpx" labelSize="28rpx" placement="row" @change="changeRadio">
            <u-radio value="0" name="0" activeColor="#3F99F7" label="立即整改"></u-radio>
            <u-radio value="1" name="1" activeColor="#3F99F7" label="限期整改"></u-radio>
          </u-radio-group>
        </view>
      </view>
      <view v-if="params.rectificationType == 0" class="item-block pt-20 pb-20 border-b-common">
        <view class="item-label"><text class="wraning-icon">*</text>整改责任单位</view>
        <!-- <view class="item-select" @click="openPicker('rectificationDept')"> -->
        <view class="item-select" @click="routeByUrl('/pagesCommon/departmentList?paramsKey=rectification')">
          <text v-if="params.rectificationDeptIdName" class="mr-10">{{params.rectificationDeptIdName}}</text>
          <text v-else class="item-default-text mr-10">请选择整改责任单位</text>
          <u-icon name="arrow-right" size="26rpx" color="#CCCCCC"></u-icon>
        </view>
      </view>
      <view v-if="params.rectificationType == 0" class="item-block pt-20 pb-20 border-b-common">
        <view class="item-label"><text class="wraning-icon">*</text>整改责任人</view>
        <!-- <view class="item-select" @click="openPicker('rectificationPeo')"> -->
        <view class="item-select" @click="routeByUrl('/pagesCommon/departmentList?paramsKey=rectification')">
          <text v-if="params.rectificationPeoIdName" class="mr-10">{{params.rectificationPeoIdName}}</text>
          <text v-else class="item-default-text mr-10">请选择整改责任人</text>
          <u-icon name="arrow-right" size="26rpx" color="#CCCCCC"></u-icon>
        </view>
      </view>
      <view v-if="params.rectificationType == 1" class="item-block pt-20 pb-20 border-b-common">
        <view class="item-label"><text class="wraning-icon">*</text>隐患下达单位</view>
        <!-- <view class="item-select" @click="openPicker('issueDept')"> -->
        <view class="item-select" @click="routeByUrl('/pagesCommon/departmentList?paramsKey=issue')">
          <text v-if="params.issueDeptIdName" class="mr-10">{{params.issueDeptIdName}}</text>
          <text v-else class="item-default-text mr-10">请选择隐患下达单位</text>
          <u-icon name="arrow-right" size="26rpx" color="#CCCCCC"></u-icon>
        </view>
      </view>
      <view v-if="params.rectificationType == 1" class="item-block pt-20 pb-20 border-b-common">
        <view class="item-label"><text class="wraning-icon">*</text>隐患下达人</view>
        <!-- <view class="item-select" @click="openPicker('issuePeo')"> -->
        <view class="item-select" @click="routeByUrl('/pagesCommon/departmentList?paramsKey=issue')">
          <text v-if="params.issuePeoIdName" class="mr-10">{{params.issuePeoIdName}}</text>
          <text v-else class="item-default-text mr-10">请选择隐患下达人</text>
          <u-icon name="arrow-right" size="26rpx" color="#CCCCCC"></u-icon>
        </view>
      </view>
      <view v-if="params.rectificationType == 1" class="item-block pt-20 pb-20 border-b-common">
        <view class="item-label"><text class="wraning-icon">*</text>下达方式</view>
        <view class="item-radio">
          <u-radio-group v-model="params.issueType" size="32rpx" labelSize="28rpx" placement="row">
            <u-radio value="0" name="0" activeColor="#3F99F7" label="快速下达"></u-radio>
            <u-radio value="1" name="1" activeColor="#3F99F7" label="进入隐患下达"></u-radio>
          </u-radio-group>
        </view>
      </view>
      <view v-if="params.issueType == 0" class="item-block pt-20 pb-20 border-b-common">
        <view class="item-label"><text class="wraning-icon">*</text>整改责任单位</view>
        <!-- <view class="item-select" @click="openPicker('rectificationDept')"> -->
        <view class="item-select" @click="routeByUrl('/pagesCommon/departmentList?paramsKey=rectification')">
          <text v-if="params.rectificationDeptIdName" class="mr-10">{{params.rectificationDeptIdName}}</text>
          <text v-else class="item-default-text mr-10">请选择整改责任单位</text>
          <u-icon name="arrow-right" size="26rpx" color="#CCCCCC"></u-icon>
        </view>
      </view>
      <view v-if="params.issueType == 0" class="item-block pt-20 pb-20 border-b-common">
        <view class="item-label"><text class="wraning-icon">*</text>整改责任人</view>
        <!-- <view class="item-select" @click="openPicker('rectificationPeo')"> -->
        <view class="item-select" @click="routeByUrl('/pagesCommon/departmentList?paramsKey=rectification')">
          <text v-if="params.rectificationPeoIdName" class="mr-10">{{params.rectificationPeoIdName}}</text>
          <text v-else class="item-default-text mr-10">请选择整改责任人</text>
          <u-icon name="arrow-right" size="26rpx" color="#CCCCCC"></u-icon>
        </view>
      </view>
      <view v-if="params.rectificationType == 1" class="item-block pt-20 pb-20 border-b-common">
        <view class="item-label"><text class="wraning-icon">*</text>整改期限</view>
        <view class="item-select" @click="() => calendarState = true">
          <text v-if="params.rectificationLimit">{{params.rectificationLimit}}</text>
          <text v-else class="item-default-text mr-10">请选择整改期限</text>
          <u-icon name="calendar" size="46rpx" color="#3F99F7"></u-icon>
        </view>
      </view>
      <view class="item-block pt-20 pb-20">
        <view class="item-label"><text class="wraning-icon">*</text>整改前</view>
        <view class="image-list">
          <u-upload :action="action" multiple :max-count="3" :file-list="fileList" @afterRead="afterRead" @delete="deleteImage"></u-upload>
        </view>
      </view>
    </view>
    <view class="form-block mt-30 pl-20 pr-20">
      <view class="pt-20" style="display: flex;">
        <view class="title-block">验收信息</view>
      </view>
      <view class="item-block pt-20 pb-20 border-b-common">
        <view class="item-label"><text class="wraning-icon">*</text>验收责任单位</view>
        <!-- <view class="item-select" @click="openPicker('cancelDept')"> -->
        <view class="item-select" @click="routeByUrl('/pagesCommon/departmentList?paramsKey=cancel')">
          <text v-if="params.cancelDeptIdName" class="mr-10">{{params.cancelDeptIdName}}</text>
          <text v-else class="item-default-text mr-10">请选择验收责任单位</text>
          <u-icon name="arrow-right" size="26rpx" color="#CCCCCC"></u-icon>
        </view>
      </view>
      <view class="item-block pt-20 pb-20 border-b-common">
        <view class="item-label"><text class="wraning-icon">*</text>验收责任人</view>
        <!-- <view class="item-select" @click="openPicker('cancelPeo')"> -->
        <view class="item-select" @click="routeByUrl('/pagesCommon/departmentList?paramsKey=cancel')">
          <text v-if="params.cancelPeoIdName" class="mr-10">{{params.cancelPeoIdName}}</text>
          <text v-else class="item-default-text mr-10">请选择验收责任人</text>
          <u-icon name="arrow-right" size="26rpx" color="#CCCCCC"></u-icon>
        </view>
      </view>
    </view>
    <view class="button-block mt-30">
      <button class="button-cancel" @click="routeBack()">取消</button>
      <button class="button-submit" @click="$u.throttle(submit, 1000)">提交</button>
    </view>
    <u-calendar :show="calendarState" mode="single" color="#3F99F7" :closeOnClickOverlay="true" @confirm="calendarConfirm" @close="calendarClose"></u-calendar>
    <u-picker :show="levelState" :columns="levelList" keyName="label" @confirm="pickerConfirm('level', $event)" @cancel="pickerCancel('level')"></u-picker>
    <u-picker :show="categoryState" :columns="categoryList" keyName="label" @confirm="pickerConfirm('category', $event)" @cancel="pickerCancel('category')"></u-picker>
    <u-picker :show="sourceState" :columns="sourceList" keyName="label" @confirm="pickerConfirm('source', $event)" @cancel="pickerCancel('source')"></u-picker>
    <u-picker :show="checkTypeState" :columns="checkTypeList" keyName="label" @confirm="pickerConfirm('checkType', $event)" @cancel="pickerCancel('checkType')"></u-picker>
    <u-picker :show="issueDeptIdState" :columns="issueDeptList" keyName="label" @confirm="pickerConfirm('issueDeptId', $event)" @cancel="pickerCancel('issueDeptId')"></u-picker>
    <u-picker :show="issuePeoIdState" :columns="issuePeoList" keyName="label" @confirm="pickerConfirm('issuePeoId', $event)" @cancel="pickerCancel('issuePeoId')"></u-picker>
    <u-picker :show="checkDeptIdState" :columns="checkDeptList" keyName="label" @confirm="pickerConfirm('checkDeptId', $event)" @cancel="pickerCancel('checkDeptId')"></u-picker>
    <u-picker :show="checkPeoIdState" :columns="checkPeoList" keyName="label" @confirm="pickerConfirm('checkPeoId', $event)" @cancel="pickerCancel('checkPeoId')"></u-picker>
    <u-picker :show="beCheckDeptIdState" :columns="beCheckDeptList" keyName="label" @confirm="pickerConfirm('beCheckDeptId', $event)" @cancel="pickerCancel('beCheckDeptId')"></u-picker>
    <u-picker :show="rectificationDeptIdState" :columns="rectificationDeptList" keyName="label" @confirm="pickerConfirm('rectificationDeptId', $event)" @cancel="pickerCancel('rectificationDeptId')"></u-picker>
    <u-picker :show="rectificationPeoIdState" :columns="rectificationPeoList" keyName="label" @confirm="pickerConfirm('rectificationPeoId', $event)" @cancel="pickerCancel('rectificationPeoId')"></u-picker>
    <u-picker :show="cancelDeptIdState" :columns="cancelDeptList" keyName="label" @confirm="pickerConfirm('cancelDeptId', $event)" @cancel="pickerCancel('cancelDeptId')"></u-picker>
    <u-picker :show="cancelPeoIdState" :columns="cancelPeoList" keyName="label" @confirm="pickerConfirm('cancelPeoId', $event)" @cancel="pickerCancel('cancelPeoId')"></u-picker>
  </view>
</template>

<script>
  import { creatDangerInfoApi } from '@/apis/danger/index.js'
  import { getDictTypeListApi, getCheckTypeDictListApi, getHtSourceDictListApi, getHtLevelDictListApi, getHtCategoryDictListApi, getDeptDictListApi, getUserDictListApi } from '@/apis/danger/common.js'
  import { getToken, getUserInfo } from '@/utils/auth.js'
  import dayjs from 'dayjs'

  export default {
    data() {
      return {
        returnState: false,
        calendarState: false,
        params: {
          rectificationLimit: dayjs().format('YYYY-MM-DD HH:mm:ss'),
          checkDate: dayjs().format('YYYY-MM-DD HH:mm:ss'),
          htName: '',
          place: '',
          level: '',
          levelName: '',
          category: '',
          categoryName: '',
          source: '',
          sourceName: '',
          checkType: '',
          checkTypeName: '',
          checkDeptId: '',
          checkDeptIdName: '',
          checkPeoId: '',
          checkPeoIdName: '',
          beCheckDeptId: '',
          beCheckDeptIdName: '',
          rectificationDeptId: '',
          rectificationDeptIdName: '',
          rectificationPeoId: '',
          rectificationPeoIdName: '',
          cancelDeptId: '',
          cancelDeptIdName: '',
          cancelPeoId: '',
          cancelPeoIdName: '',
          issueDeptId: '',
          issueDeptIdName: '',
          issuePeoId: '',
          issuePeoIdName: '',
          causeReason: '',
          description: '',
          rectificationType: '0',
          issueType: '1',
          ossImg: [],
          riskId: ''
        },
        riskName: '',
        levelState: false,
        levelList: [],
        categoryState: false,
        categoryList: [],
        sourceState: false,
        sourceList: [],
        checkTypeState: false,
        checkTypeList: [],
        checkDeptIdState: false,
        checkDeptList: [],
        checkPeoIdState: false,
        checkPeoList: [],
        beCheckDeptIdState: false,
        beCheckDeptList: [],
        rectificationDeptIdState: false,
        rectificationDeptList: [],
        rectificationPeoIdState: false,
        rectificationPeoList: [],
        cancelDeptIdState: false,
        cancelDeptList: [],
        cancelPeoIdState: false,
        cancelPeoList: [],
        issueDeptIdState: false,
        issueDeptList: [],
        issuePeoIdState: false,
        issuePeoList: [],
        action: this.uploadImageUrl,
        fileList: [],
        locationInfo: {
          address: '',
          latitude: 0,
          longitude: 0,
          name: ''
        }
      }
    },
    onLoad(options) {
      if(options.riskId) Object.assign(this.params, { riskId: options.riskId })
      this.getCheckTypeDictList()
      this.getHtSourceDictList()
      this.getHtLevelDictList()
      this.getHtCategoryDictList()
      this.getDeptDictList()
      if(getUserInfo()) {
        let userInfo = getUserInfo()
        Object.assign(this.params, {
          checkDeptId: userInfo.dept.id,
          checkDeptIdName: userInfo.dept.name,
          checkPeoId: userInfo.id,
          checkPeoIdName: userInfo.nickname,
          beCheckDeptId: userInfo.dept.id,
          beCheckDeptIdName: userInfo.dept.name,
          cancelDeptId: userInfo.dept.id,
          cancelDeptIdName: userInfo.dept.name,
          cancelPeoId: userInfo.id,
          cancelPeoIdName: userInfo.nickname,
        })
      }
    },
    onShow() {
      if(this.returnState) uni.navigateBack()
      this.riskName = JSON.parse(JSON.stringify(this.riskName))
      this.params = JSON.parse(JSON.stringify(this.params))
    },
    methods: {
      submit: function() {
        if(!this.authFormData()) return false
        let params = JSON.parse(JSON.stringify(this.params))
        creatDangerInfoApi(params).then(res => {
          this.returnState = true
          setTimeout(() => uni.navigateBack(), 500)
        }).catch(err => console.warn(err))
      },
      getCheckTypeDictList: function() {
        getCheckTypeDictListApi().then(res => {
          res.map(item => {
            if(item.value == '0') {
              this.params.checkType = item.value
              this.params.checkTypeName = item.label
            }
          })
          this.checkTypeList = [res]
        }).catch(err => console.warn(err))
      },
      getHtSourceDictList: function() {
        getHtSourceDictListApi().then(res => {
          res.map(item => {
            if(item.value == '1') {
              this.params.source = item.value
              this.params.sourceName = item.label
            }
          })
          this.sourceList = [res]
        }).catch(err => console.warn(err))
      },
      getHtLevelDictList: function() {
        getHtLevelDictListApi().then(res => {
          res.map(item => {
            if(item.value == '2') {
              this.params.level = item.value
              this.params.levelName = item.label
            }
          })
          this.levelList = [res]
        }).catch(err => console.warn(err))
      },
      getHtCategoryDictList: function() {
        getHtCategoryDictListApi().then(res => {
          res.map(item => {
            if(item.value == '1') {
              this.params.category = item.value
              this.params.categoryName = item.label
            }
          })
          this.categoryList = [res]
        }).catch(err => console.warn(err))
      },
      getDictTypeList: function() {
        getDictTypeListApi().then(res => {
          console.log('res', res)
        }).catch(err => console.warn(err))
      },
      getDeptDictList: function() {
        getDeptDictListApi({parentId: 1002}).then(res => {
          if(res.length > 0) res.map(item => Object.assign(item, {label: item.name, value: item.id}))
          this.checkDeptList = [res]
          this.beCheckDeptList = [res]
          this.rectificationDeptList = [res]
          this.cancelDeptList = [res]
          this.issueDeptList = [res]
        }).catch(err => console.warn(err))
      },
      getUserDictList: function(params, type) {
        getUserDictListApi(params).then(res => {
          if(res.length > 0) res.map(item => Object.assign(item, {label: item.nickname, value: item.id}))
          this[`${type}PeoList`] = [res]
        }).catch(err => console.warn(err))
      },
      getLocationInfo: function() {
        uni.getLocation({
          geocode: true,
          success: res => {
            uni.chooseLocation({
              latitude: res.latitude,
              longitude: res.longitude,
              success: result => {
                this.params.place = result.name
              }
            })
          }
        })
      },
      deleteImage(event) {
        this.params
        this.fileList.splice(event.index, 1)
      },
      async afterRead(event) {
        // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
        let lists = [].concat(event.file)
        let fileListLen = this.fileList.length
        lists.map((item) => {
          this.fileList.push({
            ...item,
            status: 'uploading',
            message: '上传中'
          })
        })
        for (let i = 0; i < lists.length; i++) {
          const result = await this.uploadFilePromise(lists[i].url)
          let item = this.fileList[fileListLen]
          if(result.status == 'success') {
            this.fileList.splice(fileListLen, 1, Object.assign(item, {
              status: result.status,
              message: '',
              url: result.url
            }))
            fileListLen++
          } else {
            this.fileList.splice(fileListLen, 1)
          }
        }
      },
      uploadFilePromise(url) {
        return new Promise((resolve, reject) => {
          let a = uni.uploadFile({
            url: this.uploadImageUrl,
            filePath: url,
            name: 'file',
            formData: {
              user: 'test'
            },
            header: {
              'Authorization': `Bearer ${getToken()}`,
              'tenant-id':  '1'
            },
            success: (res) => {
              let result = JSON.parse(res.data)
              if (result.code == 0) {
                this.params.ossImg.push(result.data)
                resolve({url: result.data.url, status: 'success'})
              } else {
                uni.showToast({ title: 'OSS服务器错误', icon: 'none' })
                resolve({url, status: 'fail'})
              }
            },
            fail: () => uni.showToast({ title: '图片上传失败', icon: 'none' })
          })
        })
      },
      deleteImage: function(event) {
        this.params.ossImg.splice(event.index, 1)
        this.fileList.splice(event.index, 1)
      },
      changeRadio: function() {
        Object.assign(this.params, {
          issueType: '1',
          rectificationDeptIdName: '',
          rectificationDeptId: '',
          rectificationPeoIdName: '',
          rectificationPeoId: '',
          issueDeptIdName: '',
          issueDeptId: '',
          issuePeoIdName: '',
          issuePeoId: ''
        })
      },
      openPicker: function(type) {
        if(this[`${type}List`][0].length) {
          this[`${type}IdState`] = true
        } else {
          uni.showToast({ title: '暂无数据', icon: 'none' })
        }
      },
      pickerConfirm: function(type, event) {
        if(type == 'checkDeptId') {
          this.params.checkPeoId = ''
          this.params.checkPeoIdName = ''
          this.getUserDictList({ deptId: event.value[0].value }, 'check')
        }
        if(type == 'rectificationDeptId') {
          this.params.rectificationPeoId = ''
          this.params.rectificationPeoIdName = ''
          this.getUserDictList({ deptId: event.value[0].value }, 'rectification')
        }
        if(type == 'cancelDeptId') {
          this.params.cancelPeoId = ''
          this.params.cancelPeoIdName = ''
          this.getUserDictList({ deptId: event.value[0].value }, 'cancel')
        }
        if(type == 'issueDeptId') {
          this.params.issuePeoId = ''
          this.params.issuePeoIdName = ''
          this.getUserDictList({ deptId: event.value[0].value }, 'issue')
        }
        this.params[type] = event.value[0].value
        this.params[`${type}Name`] = event.value[0].label
        this[`${type}State`] = false
      },
      pickerCancel: function(type) {
        this[`${type}State`] = false
      },
      calendarConfirm: function(event) {
        this.params.rectificationLimit = event[0] + " " + "23:59:59"
        this.calendarState = false
      },
      calendarClose: function() {
        this.calendarState = false
      },
      routeByUrl: function(url) {
        uni.navigateTo({ url })
      },
      routeBack: function() {
        uni.navigateBack()
      },
      authFormData: function() {
        let params = this.params
        if(!params.htName) {
          uni.showToast({ title: '请输入隐患名称', icon: 'none' })
          return false
        }
        if(!params.levelName) {
          uni.showToast({ title: '请选择隐患等级', icon: 'none' })
          return false
        }
        if(!params.categoryName) {
          uni.showToast({ title: '请选择隐患类别', icon: 'none' })
          return false
        }
        if(!params.sourceName) {
          uni.showToast({ title: '请选择隐患来源', icon: 'none' })
          return false
        }
        if(!params.place) {
          uni.showToast({ title: '请输入/选择隐患地点', icon: 'none' })
          return false
        }
        if(!params.checkTypeName) {
          uni.showToast({ title: '请选择检查类型', icon: 'none' })
          return false
        }
        if(!params.checkDeptIdName) {
          uni.showToast({ title: '请选择检查单位', icon: 'none' })
          return false
        }
        if(!params.checkPeoIdName) {
          uni.showToast({ title: '请选择检查人', icon: 'none' })
          return false
        }
        // if(!this.riskName) {
        //   uni.showToast({ title: '请选择所属风险点', icon: 'none' })
        //   return false
        // }
        if(!params.beCheckDeptIdName) {
          uni.showToast({ title: '请选择所属单位', icon: 'none' })
          return false
        }
        if(params.rectificationType == 0 && !params.rectificationDeptIdName) {
          uni.showToast({ title: '请选择整改责任单位', icon: 'none' })
          return false
        }
        if(params.rectificationType == 0 && !params.rectificationPeoIdName) {
          uni.showToast({ title: '请选择整改责任单位', icon: 'none' })
          return false
        }
        if(params.rectificationType == 1 && !params.issueDeptIdName) {
          uni.showToast({ title: '请选择隐患下达单位', icon: 'none' })
          return false
        }
        if(params.rectificationType == 1 && !params.issuePeoIdName) {
          uni.showToast({ title: '请选择隐患下达人', icon: 'none' })
          return false
        }
        if(params.issueType == 0 && !params.rectificationDeptIdName) {
          uni.showToast({ title: '请选择整改责任单位', icon: 'none' })
          return false
        }
        if(params.issueType == 0 && !params.rectificationPeoIdName) {
          uni.showToast({ title: '请选择整改责任人', icon: 'none' })
          return false
        }
        if(params.rectificationType == 1 && !params.rectificationLimit) {
          uni.showToast({ title: '请选择整改期限', icon: 'none' })
          return false
        }
        if(this.fileList.length <= 0) {
          uni.showToast({ title: '请上传整改前照片', icon: 'none' })
          return false
        }
        if(!params.cancelDeptIdName) {
          uni.showToast({ title: '请选择验收责任单位', icon: 'none' })
          return false
        }
        if(!params.cancelPeoIdName) {
          uni.showToast({ title: '请选择验收责任人', icon: 'none' })
          return false
        }
        return true
      }
    }
  }
</script>

<style>
  page {
    background-color: #F4F4F4;
  }
  .u-radio:last-child {
    margin-left: 30rpx;
  }
  .u-radio__text {
    font-size: 28rpx !important;
    /* line-height: 42rpx !important; */
  }
  .u-button {
    background-color: #3F99F7 !important;
  }
  .u-upload__wrap__preview__image {
    width: 160rpx !important;
    height: 160rpx !important;
  }
</style>

<style lang="scss" scoped>
  .content {
    .text-over {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .form-block {
      border-radius: 6rpx;
      background-color: #FFFFFF;
      .title-block {
        font-size: 30rpx;
        line-height: 42rpx;
        color: #222222;
        font-weight: 500;
        background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, 0) 50%, #C5DBFF 50%, #C5DBFF);
      }
      .item-block {
        display: flex;
        align-items: center;
        justify-content: space-between;
        .item-label {
          font-size: 28rpx;
          line-height: 40rpx;
          color: #333333;
          .wraning-icon {
            color: #FE0303;
            margin-right: 5rpx;
          }
        }
        .item-input {
          max-width: 420rpx;
          font-size: 28rpx;
          line-height: 40rpx;
          color: #333333;
        }
        .placeholder {
          font-size: 28rpx;
          line-height: 40rpx;
          color: #999999;
        }
        .item-select {
          max-width: 420rpx;
          display: flex;
          align-items: center;
          font-size: 28rpx;
          line-height: 40rpx;
          color: #333333;
          .item-default-text {
            color: #999999;
          }
        }
        .image-list {
          max-width: 530rpx;
        }
      }
    }
    .button-block {
      display: flex;
      align-items: center;
      justify-content: space-between;
      .button-cancel {
        width: 334rpx;
        height: 80rpx;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 26rpx;
        color: #FFFFFF;
        border-radius: 8rpx;
        background-color: #BBBBBB;
      }
      .button-cancel::after {
        border: none
      }
      .button-submit {
        @extend .button-cancel;
        background-color: #3F99F7;
      }
      .button-submit::after {
        border: none;
      }
    }
  }
</style>
